package com.zygh.policeasset.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.mapper.CompanyMapper;
import com.zygh.policeasset.pojo.Company;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/CompanyService.class */
public class CompanyService {
    @Autowired
    CompanyMapper companyMapper;

    public List<Company> findAll() {
        return this.companyMapper.findAll("");
    }

    public List<Company> findByCp() {
        return this.companyMapper.findByCp();
    }

    public List<Company> findById(Integer id) {
        return this.companyMapper.findById(id);
    }

    public PageInfo findAll(String companyName, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(this.companyMapper.findAll(companyName));
    }

    public List<Company> findAllBycompanyName(String companyName) {
        return this.companyMapper.findAll(companyName);
    }

    public Integer add(Company company) {
        int res = 0;
        try {
            if (this.companyMapper.getAdd(company.getCompanyName(), -1) == null) {
                res = this.companyMapper.add(company);
            } else {
                res = -1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Integer.valueOf(res);
    }

    public Integer addresId(Company company) {
        this.companyMapper.add(company);
        return company.getId();
    }

    public Integer update(Company company) {
        int res = 0;
        try {
            if (this.companyMapper.getAdd(company.getCompanyName(), company.getId().intValue()) == null) {
                res = this.companyMapper.update(company);
            } else {
                res = -1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Integer.valueOf(res);
    }

    public Integer remove(int id) {
        return Integer.valueOf(this.companyMapper.delete(Integer.valueOf(id)));
    }
}